from django.contrib import admin
# 导入模型类
from .models import Book, Author
# 定义模型管理类
class BookManager(admin.ModelAdmin):
    # 列表页中显示的字段
    list_display = ['id', 'title', 'pub', 'price', 'market_price', 'is_active']
    # 可以通过哪些字段进入到修改页面
    list_display_links = ['title']
    # 添加过滤器，可以按照指定的字段筛选数据
    list_filter = ['pub']
    # 添加搜索框
    search_fields = ['title']
    # 设置可以在列表页直接修改的字段
    list_editable = ['price', 'market_price']
class AuthorManager(admin.ModelAdmin):
    list_display = ['id', 'name', 'age', 'email']
    list_display_links = ['name']
    search_fields = ['name']
    list_editable = ['email', 'age']
# 将模型类注册到admin站点
admin.site.register(Book, BookManager)
admin.site.register(Author, AuthorManager)
